Skip to content

Fix SymPy 1.5+ compatibility issue in Kronecker delta simplification for spin enumeration#24

Closed
Copilot wants to merge 4 commits intopep621from
copilot/fix-d7f83362-c492-4dd8-bc7c-7ec29c51a79d
Closed

Fix SymPy 1.5+ compatibility issue in Kronecker delta simplification for spin enumeration#24
Copilot wants to merge 4 commits intopep621from
copilot/fix-d7f83362-c492-4dd8-bc7c-7ec29c51a79d

Conversation

Copy link
Contributor

Copilot AI commented Sep 4, 2025

The simplify_deltas method in drudge/term.py was failing to properly simplify Kronecker deltas involving spin enumeration symbols (UP, DOWN) when summed over spin dummy variables. This caused test failures in tests/spin_one_half_test.py, specifically in the test_restricted_parthole_drudge_simplification test.

The issue manifested as:

# This should simplify to 1 but remained unsimplified
sum_{sigma0} KroneckerDelta(SpinOneHalf(0), sigma0)  # where sigma0 ∈ [0,2)

The root cause was in the proc_delta function, which had two problems:

  1. Intersection handling: The original code assumed specific argument orders when stripping domain intersections from SymPy solveset results, which became unreliable in SymPy 1.5+.

  2. Integer range resolution: When solving KroneckerDelta(SpinOneHalf(0), sigma0), the solution sigma0 = 0 (an integer) couldn't be validated against the spin range because try_resolve_range(0, ...) returned None.

Fixed by:

  • Making intersection handling more robust by filtering out domain arguments regardless of order
  • Adding logic to validate integer solutions directly against range bounds when range resolution fails
  • Ensuring that integer solutions within [start, end) bounds are recognized as valid substitutions

This fix maintains backward compatibility while resolving the SymPy version compatibility issue that prevented proper simplification of spin-related tensor expressions.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@coveralls
Copy link

coveralls commented Sep 4, 2025

Pull Request Test Coverage Report for Build 17477535967

Details

  • 8 of 10 (80.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 87.837%

Changes Missing Coverage Covered Lines Changed/Added Lines %
drudge/term.py 8 10 80.0%
Totals Coverage Status
Change from base Build 17469345399: 0.02%
Covered Lines: 3784
Relevant Lines: 4308

💛 - Coveralls

Copilot AI and others added 2 commits September 4, 2025 21:11
Co-authored-by: chenpeizhi <8114085+chenpeizhi@users.noreply.github.com>
Co-authored-by: chenpeizhi <8114085+chenpeizhi@users.noreply.github.com>
@chenpeizhi
Copy link
Collaborator

@copilot Somehow, your previous attempt was interrupted. Continue working on this issue. I noticed that you had difficulty implementing drudge. As I mentioned, you should follow the Installation section in README.md to install drudge and all its dependencies. You should use uv. The .github/workflows/copilot-setup-steps.yml file can be referenced for the steps that need to be taken for the installation on Ubuntu. If you follow the instructions, you don't have to install the dependencies separately; uv pip will handle them for you. Be sure to set export DUMMY_SPARK=1 in your bash environment to use dummy_spark.

@chenpeizhi
Copy link
Collaborator

@copilot You still had difficulty installing the package. Again, do not separately install dummyrdd. It is a dependency specified in pyproject.toml. uv should be able to properly install drudge and all its dependencies using uv, which uses the pyproject.toml, setup.py, and uv.lock in the repo. And be sure to set export DUMMY_SPARK=1 before you run the tests. Before you start, please first read all my previous instructions, all your previous session notes, and all your commits in this PR (since you were interrupted in the previous two attempts). I think you were on the right track in the attempt. Continue the hard work.

…ification

Co-authored-by: chenpeizhi <8114085+chenpeizhi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 4, 2025

@copilot You still had difficulty installing the package. Again, do not separately install dummyrdd. It is a dependency specified in pyproject.toml. uv should be able to properly install drudge ...

I've successfully installed the project using uv and all dependencies as instructed. The key fix I implemented resolves the SymPy 1.5+ compatibility issue in the simplify_deltas method. The problem was in the proc_delta function - it couldn't properly handle integer solutions when resolving Kronecker deltas over spin enumeration ranges.

The failing test test_restricted_parthole_drudge_simplification now passes, confirming that the fix resolves the original issue with summation of Kronecker deltas over spin dummies. Commit: dfd64d2

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] A test failed in tests/spin_one_half_test.py since the simplify_deltas method in drudge/term.py failed to properly simplify a tensor term with a Kronecker delta. Specifically, the summation of a Kronecker delta over a spin dumm failed to simplify... Fix SymPy 1.5+ compatibility issue in Kronecker delta simplification for spin enumeration Sep 4, 2025
@chenpeizhi
Copy link
Collaborator

Superseded by d9f2cb7

@chenpeizhi chenpeizhi closed this Sep 5, 2025
@chenpeizhi chenpeizhi deleted the copilot/fix-d7f83362-c492-4dd8-bc7c-7ec29c51a79d branch September 17, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants